package de.develop.server;

import java.util.*;
import javax.swing.*;

/**
 * UpdateClientCountTask is a task for updating a label with information about the number of connected clients.
 *
 * @author Nuno Freitas (nunofreitas@gmail.com)
 */
public class UpdateClientCountTask extends TimerTask
{

    protected JLabel clientsLabel;
    protected GameServer chatServer;

    /**
     * Creates a new instance of UpdateClientCountTask.
     *
     * @param chatServer the chat server
     * @param clientsLabel the label to be updated
     */
    public UpdateClientCountTask( GameServer chatServer, JLabel clientsLabel )
    {
        this.chatServer = chatServer;
        this.clientsLabel = clientsLabel;
    }

    /**
     * Updates the label with the number of connected clients.
     */
    public void run()
    {
        int count = this.chatServer.getClientCount();
        String msg = count + " client" + ( ( count != 1 ) ? "s" : "" );
        this.clientsLabel.setText( msg );
    }
}
